﻿
@{
    ViewData["Title"] = "SasleView";
}
@{
    Layout = null;
}
<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <link href="~/libs/layui-v2.5.6/layui/css/layui.css" rel="stylesheet" />
    <script src="~/libs/jquery/jquery.js"></script>
    <script src="~/libs/layui-v2.5.6/layui/layui.js"></script>
</head>
<body>
    <form class="layui-form layui-row layui-col-space16">
        <div class="layui-col-md2">
            <div class="layui-input-wrap">
                <input type="text" name="warehouseCode" value="" placeholder="请输入仓库编码" class="layui-input" lay-affix="clear" id="workshopCode">
            </div>
        </div>
        <div class="layui-col-md2">
            <div class="layui-input-wrap">
                <input type="text" name="warehouseName" value="" placeholder="请输入仓库名称" class="layui-input" lay-affix="clear" id="workshopCode">
            </div>
        </div>
        <div class="layui-btn-container layui-col-xs12">
            <button class="layui-btn" lay-submit lay-filter="demo-table-search">搜索</button>
            <button type="reset" class="layui-btn layui-btn-primary">重置</button>
            <button type="button" class="layui-btn  layui-btn-primary" lay-on="test-page-custom">添加</button>
        </div>
    </form>
    <table class="layui-hide" id="demo" lay-filter="test">
    </table>
    <script src="~/libs/layui-v2.5.6/layui/layui.js"></script>
    <script type="text/html" id="TPL-treeTable-demo-tools">
        <div class="layui-btn-container">
          <a class="layui-btn layui-btn-xs" lay-event="updateData">修改</a>
          <a class="layui-btn layui-btn-xs" lay-event="deleteData">删除</a>
        </div>
    </script>
    <script>
        layui.use(['table', 'form', 'layer', 'dropdown'], function () {
            var table = layui.table;
            var form = layui.form;
            var dropdown = layui.dropdown;
            var layer = layui.layer
            var datas = [];
            // 创建表格实例
            var inst = table.render({
                elem: '#demo',
                url: '/SuJiaHao/GetSasleList',
                cols: [[
                    { field: 'rtCode', width: 100, title: '退货单编码', },
                    { field: 'rtName', width: 100, title: '退货单名称' },
                    { field: 'soCode', width: 100, title: '销售订单编号', },
                    { field: 'clientName', width: 100, title: '客户名称' },
                    { field: 'warehouseName', width: 100, title: '仓库' },
                    { field: 'locationName', width: 100, title: '库区', },
                    { field: 'areaName', width: 100, title: '库位', },
                    { field: 'rtDate', width: 100, title: '退货日期', },
                    { field: 'status', width: 100, title: '单据状态', },
                    { field: 'writes', title: '操作', width: 200, toolbar: "#TPL-treeTable-demo-tools" }
                ]],
                page: {
                    limit: 5,
                    limits: [5, 10, 15, 20, 25],
                    prev: '上一页',
                    next: '下一页',
                    first: '首页',
                    last: '尾页'
                },
                request: {
                    pageName: 'pageIndex',
                    limitName: 'pageSize'
                },
                parseData: function (res) {
                    console.log(res)
                    return {
                        "code": res.code, //解析接口状态
                        "count": res.data.totalCount, //解析数据长度
                        "data": res.data.pageList//解析数据列表
                    };
                },
            });
            // 搜索提交
            form.on('submit(demo-table-search)', function (data) {
                var field = data.field; // 获得表单字段
                // 执行搜索重载
                table.reload('demo', {
                    page: {
                        curr: 1 // 重新从第 1 页开始
                    },
                    where: field // 搜索的字段
                });
                layer.msg('搜索成功');
                return false; // 阻止默认 form 跳转
            });
            // 单元格工具事件
            table.on('tool(test)', function (obj) {
                var layEvent = obj.event; // 获得 lay-event 对应的值
                var trData = obj.data;
                var tableId = obj.config.id;
                if (layEvent === "deleteData") {
                    console.log(trData.id);
                    layer.confirm("确定删除吗？", function (index) {
                        $.ajax({
                            url: "/SuJiaHao/DeleteSasle?id=" + trData.id,
                            type: "get",
                            async: true,
                            success: res => {
                                console.log(res);
                                if (res.data > 0) {
                                    layer.msg('删除成功');
                                } else {
                                    layer.msg('删除失败');
                                }
                            }
                        });
                        obj.del(); // 删除当前行
                        layer.close(index); // 关闭弹出层
                    });
                }
                else if (layEvent === "updateData") {
                    // 打开编辑页面
                    layer.open({
                        type: 2,
                        title: '修改客户',
                        shadeClose: true,
                        shade: 0.8,
                        area: ['600px', '500px'],
                        content: '/SuJiaHao/SasleUpdateView?id=' + trData.id,
                        end: function () {
                            location.reload();
                        },
                    });

                }
            });
        });
    </script>
    @*  添加 *@
    <script>
        layui.use(function () {
            var $ = layui.$;
            var layer = layui.layer;
            var table = layui.table;
            var util = layui.util;
            var form = layui.form;
            // 事件
            util.on('lay-on', {
                'test-page-custom': function () {
                    layer.open({
                        type: 2,
                        area: ['500px', '500px'],
                        resize: false,
                        shadeClose: true,
                        title: '销售退货添加',
                        content: '/SuJiaHao/SasleAddView',
                        end: function () {
                            location.reload();
                        },
                    });
                }
            })
        });
    </script>
</body>
</html>
